package com.lucien.admin.controller.system;

import com.lucien.common.result.GlobalResult;
import com.lucien.system.domain.SysGroupNotice;
import com.lucien.system.service.SysGroupNoticeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/notice")
@Api(tags = "群公告接口")
public class SysGroupNoticeController {

    @Autowired
    private SysGroupNoticeService noticeService;

    @PostMapping("/insert")
    @ApiOperation(value = "添加群公告")
    public GlobalResult insert(Integer groupId, Integer userId, String title, String content){
        int result = noticeService.insertNotice(groupId, userId, title, content);
        return GlobalResult.success(result);
    }

    @GetMapping("/list/{groupId}")
    @ApiOperation(value = "获取群公告")
    public GlobalResult listNotice(@PathVariable("groupId") Integer groupId){
        List<SysGroupNotice> notices = noticeService.listNotice(groupId);
        return GlobalResult.success("获取群公告成功", notices);
    }

    @GetMapping("/del/{id}")
    @ApiOperation(value = "删除公告")
    public GlobalResult delNotice(@PathVariable("id") Long id){
        int result = noticeService.delNotice(id);
        return GlobalResult.success(result);
    }

    @PostMapping("/update/{id}")
    @ApiOperation(value = "更新公告")
    public GlobalResult updateNotice(@PathVariable("id") Long id, String title, String content){
        int result = noticeService.editNotice(id, title, content);
        return GlobalResult.success("更新成功", result);
    }
}
